<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 1.引入链接 -->
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>

<body>
    <!-- 2.创建div模板 -->
    <div id="app">
        <input type="text" v-model="value" @keydown.enter="addVal()">
        <div>
            <h1>正在进行 <span>{{fang}}</span></h1>
            <ul>
                <li v-for="(item,index) in list" :key="index" style="display:flex;" v-show="!item.flag">
                    <input type="checkbox" v-model="item.flag" @click="gap(index)">
                    <p style="margin:0 50px;">{{item.title}}</p>
                    <button size="mini" type="primary" @click="del(index)">删除</button>
                </li>
            </ul>
            <h1>已经完成 <span>{{list.length-fang}}</span></h1>
            <ul>
                <li v-for="(item,index) in list" :key="index" style="display:flex;" v-show="item.flag">
                    <input type="checkbox" v-model="item.flag" @click="gap(index)">
                    <p style="margin:0 50px;">{{item.title}}</p>
                    <button size="mini" type="primary" @click="del(index)">删除</button>
                </li>
            </ul>
        </div>
    </div>
</body>

</html>
<script>
    /* 3.实例化vue */
    new Vue({
        el: '#app',
        data: {
            value: '',
            list: JSON.parse(localStorage.getItem('list')) || [],
            show:false
        },
        methods: {
            // 添加
            addVal() {
                if (this.value == '') {
                    return alert('内容不能为空')
                }
                let obj = { title: this.value, flag: false, edit: false }
                this.list.push(obj)  
                this.setCity()
                this.value=''  //清空
            },
            //本地存储
            setCity() {
                localStorage.setItem('list', JSON.stringify(this.list))
            },
            //切换
            gap(index){
                this.list[index].flag=!this.list[index].flag
            },
            //删除
            del(key){
                this.list.splice(key,1)
            }
        },
        mounted() {

        },
        computed:{
            fang(val){
                console.log(val);
                let a=val.list.filter(item=>{
                    return item.flag==false
                })
                console.log(a);
                return a.length  //5,4,3
            }
        }
    })
</script>